﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary.Randoms
{
    public class RandomQuestions
    {
        char[] op = { '+', '-', '*', '/' };
        Random ran = new Random();

        public int count { get; set; }
        public int Range1 { get; set; }
        public int Range2 { get; set; }
        public int operators { get; set; } = 2;
        public List<string> Value = new List<string>();
        public List<string> RunValue()
        {
            return Value;
        }
        public List<string> RunAll(int count, int Range1, int Range2)
        {
            return GetRandom(count, Range1, Range2, out string value);

        }
        public List<string> GetRandom(int count, int Range1, int Range2, out string value)
        {
            string t = "";
            value = null;
            List<string> vs = new List<string>();
            for (int i = 0; i < count; i++)
            {
                int num1 = ran.Next(Range1, Range2);
                int num2 = ran.Next(Range1, Range2);
                var ranoperators = op[ran.Next(operators)];
                if (ranoperators == '+')
                {
                    t = num1 + op[0].ToString() + num2 + "= ?";
                    value = (num1 + num2).ToString();
                }
                else
                {
                    if (num1 > num2)
                    {
                        t = num1 + op[1].ToString() + num2 + "= ?";
                        value = (num1 - num2).ToString();
                    }
                    else
                    {
                        t = num2 + op[1].ToString() + num1 + "= ?";
                        value = (num2 - num1).ToString();
                    }
                }
                vs.Add(t);
                Value.Add(value);
            }
            return vs;
        }
    }
}
